package com.wen.tian.controller;

import com.wen.tian.bean.Result;
import com.wen.tian.bean.ResultUtil;
import com.wen.tian.enums.CommonEnum;
import com.wen.tian.exception.CustomException;
import com.wen.tian.service.LoginService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author tww
 * ClassName: TestController.java、
 * createTime: 2020年11月04日 22:02:40
 **/

@RestController
public class TestController {

    @Autowired
    private LoginService loginService;

    @GetMapping("test")
    public String test() {
        if (1 == 1) {
            throw new CustomException(CommonEnum.NOT_FOUND);
        }
        return "hello";
    }

    @GetMapping("test4")
    public String test4() {
        if (1 == 1) {
            throw new CustomException(CommonEnum.PHONE_NOT_FOUND);
        }
        return "hello";
    }

    @GetMapping("test2")
    public String test2() {
        String s = null;
        s.equals("s");
        return "hello";
    }


    @GetMapping("test3")
    public String test3() {
        int i = 1 / 0;
        return "hello";
    }

    @GetMapping("test5")
    public Result test5() {
        try {
            int i = 1 / 0;
            return ResultUtil.success();
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("/by zero");
        }
    }

    private static final Logger logger = LoggerFactory.getLogger(TestController.class);

    public static void main(String[] args) {

        logger.error("error");
        logger.warn("warn");
        logger.info("info");
        logger.debug("debug");
        logger.trace("trace");
    }


    @GetMapping("getdata")
    @ResponseBody
    public Result getdata() {
        return null;
    }


}
